#ifndef NETWORKMANAGER_H
#define NETWORKMANAGER_H

#include <iostream>
#include <ncurses.h>

#include "raknet/MessageIdentifiers.h"
#include "raknet/RakNetworkFactory.h"
#include "raknet/RakPeerInterface.h"
#include "raknet/RakNetTypes.h"

#include "raknet/BitStream.h"
#include "raknet/RakSleep.h"

#include "message.h"
#include "database.h"
#include "objectManager.h"
#include "networkBasics.h"
#include "networkClients.h"



class objectManager; // chicken-egg-problem
class database;



using namespace std;

class networkManager : networkBasics {


    public:


        networkManager();
        virtual ~networkManager();

        void Init(int pMaxClients, string pHost, int pPort);
        void Tick(void);
        void TickSecond(void);
        void Draw(int row);
        void IntroduceMessage(message *pMsgSystem);
        void IntroduceSQL(database *pDataManager);
        void IntroduceObjManager(objectManager *pObjManager);

         int getConnections(void);

        bool debug;



    protected:


    private:


        // vars
        bool isInit;
        long runningID;

        vector<networkClients> player;
        int playerMAX, playerCNT;


        // pointer
        message *msgSystem;
        objectManager *objManager;
        RakPeerInterface* peer;
        database *dataBase;
        Packet *packet;


        // functions
        void readMessage(Packet *packet, int pPlayerID);
        void sendMessage(int pType, int pPlayerID);
         int clientAdd(Packet *packet);
        void clientKill(int pPlayerIndex);
         int getPlayerID(Packet *packet);
         int getPlayerIndex(int pPlayerID);


        // buffer
        StructMsgChat bufferChatRelay;



};



#endif // SRNETWORKSERVER_H
